package com.veo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.veo.entity.Cart;
import com.veo.entity.CartVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface CartMapper extends BaseMapper<Cart> {

    //根据用户查询购物车
    @Select("SELECT\n" +
            "\tbsc.*,\n" +
            "\tbsb.NAME bookName,\n" +
            "\tbsb.img_url img_url,\n" +
            "\tbsb.new_price new_price \n" +
            "FROM\n" +
            "\tbs_cart bsc\n" +
            "\tLEFT JOIN bs_book bsb ON bsc.book_id = bsb.id \n" +
            "WHERE\n" +
            "\tbsc.user_id = #{userId};")
    List<CartVo> findCartListByUserId(Integer userId);

    //根据商品的id查询购物车
    @Select({
            "<script>"+
                "SELECT\n" +
                "\tbsc.*,\n" +
                "\tbsb.NAME bookName,\n" +
                "\tbsb.img_url img_url,\n" +
                "\tbsb.new_price new_price \n" +
                "FROM\n" +
                "\tbs_cart bsc\n" +
                "\tLEFT JOIN bs_book bsb ON bsc.book_id = bsb.id \n" +
                "WHERE bsc.book_id in\n" +
                "<foreach collection='ids' open='(' item='item' separator=',' close=')'> #{item}</foreach>"+
            "</script>"})
    List<CartVo> findCartVoByIds(@Param("ids") List<String> ids);
}
